﻿using B.MES.Customer.Application.IApplication;
using B.MES.Customer.Domain.DTO;
using B.MES.Customer.Domain;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using B.MES.Customer.Application.Application;
using MiniExcelLibs;
using Mysqlx.Crud;
using NPOI.HSSF.Record.Chart;

namespace B.MES.Customer.Read.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialsController : ControllerBase
    {
        private readonly ISqlSugarClient _db;
        private readonly IMaterialApplication _materialApplication;
        public MaterialsController(IMaterialApplication materialApplication)
        {
            _materialApplication = materialApplication;
        }


        /// <summary>
        /// 带分页的物料查询
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="matCode">物料编号</param>
        /// <param name="matName">物料名称</param>
        /// <param name="matModel">规格型号</param>
        /// <param name="matBrand">品牌</param>
        /// <returns>分页查询结果</returns>
        [HttpGet]
        public IActionResult GetMaterials(int pageIndex, int pageSize, string? matCode = null, string? matName = null, string? matModel = null, string? matBrand = null)
        {
            var list = _materialApplication.GetMaterials(pageIndex, pageSize, matCode, matName, matModel, matBrand);
            return Ok(list);
        }

        /// <summary>
        /// 绑定物料属性表的下拉框
        /// </summary>
        /// <returns>返回物料属性表数据</returns>
        [HttpGet]
        public IActionResult GetMatattrShow()
        {
            return Ok(_materialApplication.GetMatattrShow());
        }
        /// <summary>
        /// 绑定物料类别表的下拉框
        /// </summary>
        /// <returns>返回物料类别表数据</returns>
        [HttpGet]
        public IActionResult GetMatTypeinfoShow()
        {
            return Ok(_materialApplication.GetMatTypeinfoShow());
        }
        /// <summary>
        /// 绑定物料单位表的下拉框
        /// </summary>
        /// <returns>返回物料单位表数据</returns>
        [HttpGet]
        public IActionResult GetMatUnitInfoShow()
        {
            return Ok(_materialApplication.GetMatUnitInfoShow());
        }

        /// <summary>
        /// 添加物料表
        /// </summary>
        /// <param name="material">需要添加的物料数据</param>
        /// <returns>受影响的行数</returns>
        [HttpPost]
        public IActionResult AddMaterial(Material material)
        {
            return Ok(_materialApplication.AddMaterial(material));
        }
    }
}
